import math


def is_prime(num):
    assert num > 0
    for factor in range(2, int(math.sqrt(num)) + 1):
        if num % factor == 0:
            return False
    return True if num != 1 else False


def main():
    f = None
    try:
        f = open('data/bbb.txt', 'w', encoding='utf-8')
        for number in range(1, 10000):
            if is_prime(number):
                f.write(str(number) + '\n')
    except IOError as e:
        print('IOError: ', e, end='\n')
    finally:
        if f:
            f.close()
    print('Finished!')


if __name__ == '__main__':
    main()
